
export const $$eventMap = new Map();

export function $$event(tag: any, data: any) {
    const listener = $$eventMap.get(tag);
    if (listener) listener.forEach((fn: any) => fn(data));
}

export function $$on(tag: any, fn: any) {
    let listener = $$eventMap.get(tag);
    if (!listener) {
        listener = new Set();
        $$eventMap.set(tag, listener);
    }
    listener.add(fn);
}

export function $$off(tag: any, fn: Function) {
    const listener = $$eventMap.get(tag);
    if (listener) listener.delete(fn);
};

export async function json(fileName: string) {
    let response = await fetch(`../data/${fileName}.json`);
    let data = await response.json();
    return data;
};

export function hideBanners(e: any) {
    document
        .querySelectorAll(".banner.visible")
        .forEach((b) => b.classList.remove("visible"));
};
